﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace loveMotorcade.web.Classes
{
    public class AjaxResultForSWFUpload
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="result">处理结果 ok,error</param>
        /// <param name="content">处理结果信息</param>
        /// <param name="code">代码</param>
        /// <returns></returns>
        public static JsonResult json(string result, string content, string code = "")
        {
            return new JsonResult() { Data = "({code:'" + code + "',result:'" + result + "',content:'" + content + "'})", JsonRequestBehavior= JsonRequestBehavior.AllowGet };
        }

        public static JsonResult jsonOk(string content = "")
        {
            return json("ok", content);
        }

        public static JsonResult jsonError(string content = "")
        {
            return json("error", content);
        }

    }
    public class myJson
    {
        static JsonResult JsonResult = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        static Dictionary<string, object> data = new Dictionary<string, object>();

        public static JsonResult success(object content = null, resultActionEnum action = resultActionEnum.none, string jsonType = "applaction/json")
        {
            if (content == null) content = "成功";
            data["result"] = resultTypeEnum.SUCCESS.ToString();
            data["content"] = content;
            data["action"] = action.ToString();
            JsonResult.Data = data;
            if (jsonType != null)
            {
                JsonResult.ContentType = jsonType;
            }
            return JsonResult;
        }

        public static JsonResult error(object content = null, resultActionEnum action = resultActionEnum.none, string jsonType = "applaction/json")
        {
            if (content == null) content = "失败";
            data["result"] = resultTypeEnum.ERROR.ToString();
            data["content"] = content;
            data["action"] = action.ToString();
            JsonResult.Data = data;
            if (jsonType != null)
            {
                JsonResult.ContentType = jsonType;
            }
            return JsonResult;
        }
    }
    public enum resultTypeEnum
    {
        SUCCESS,
        ERROR,
    }

    public enum resultActionEnum
    {
        none,
        reload,
        updata,
        relogin
    }
}